<?php

class PHPRizhi {
    public function __construct($sPath) {
        $this->sPath = $sPath;
    }

    protected $sPath;

    /**
     * 向文件中追加内容
     *
     * @param string $sPath 文件路径
     * @param string $sContent 内容
     */
    protected function append2File($sPath, $sContent) {
        $fp = fopen($sPath, "ab");
        flock($fp, LOCK_EX);
        fwrite($fp,$sContent);
        flock($fp, LOCK_UN);
        fclose($fp);
    }

    /**
     * 追加一行日志
     *
     * @param string $sContent 内容
     */
    public function writeLine($sContent) {
        $sLine = sprintf("%s(%s): %s\n", strftime("%Y-%m-%d %H:%M:%S"), getmypid(), $sContent);
        $this->append2File(strftime($this->sPath), $sLine);
    }
}

?>